#include <iostream>

using namespace std;

const int N = 30010 , M = 30;
int n , m;
int v[M] , p[M];
int dp[N];
int main()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i ++) cin >> v[i] >> p[i];
    for(int i = 1;i <= m;i ++)
    {
        for(int j = n;j >= v[i];j --)
        {
            dp[j] = max(dp[j] , dp[j - v[i]] + v[i] * p[i]);
        }
    }
    cout << dp[n] << endl;
    return 0;
}